<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libfuse: example/cuse.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libfuse
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',false,false,'search.php','Search');
});
</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_cfafba98a580ce4b62f8a6fa96d7cbb0.html">example</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">cuse.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;cuse_lowlevel.h&gt;</code><br />
<code>#include &lt;<a class="el" href="fuse__opt_8h_source.html">fuse_opt.h</a>&gt;</code><br />
<code>#include &lt;stddef.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
<code>#include &lt;unistd.h&gt;</code><br />
<code>#include &lt;errno.h&gt;</code><br />
<code>#include &quot;<a class="el" href="ioctl_8h_source.html">ioctl.h</a>&quot;</code><br />
</div>
<p><a href="cuse_8c_source.html">Go to the source code of this file.</a></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>This example demonstrates how to implement a character device in userspace ("CUSE"). This is only allowed for root. The character device should appear in /dev under the specified name. It can be tested with the <a class="el" href="cuse__client_8c.html">cuse_client.c</a> program.</p>
<p>Mount the file system with: </p><pre class="fragment">cuse -f --name=mydevice
</pre><p>You should now have a new /dev/mydevice character device. To "unmount" it, kill the "cuse" process.</p>
<p>To compile this example, run </p><pre class="fragment">gcc -Wall cuse.c `pkg-config fuse3 --cflags --libs` -o cuse
</pre><h2>Source code</h2>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  CUSE example: Character device in Userspace</span></div><div class="line"><span class="comment">  Copyright (C) 2008-2009  SUSE Linux Products GmbH</span></div><div class="line"><span class="comment">  Copyright (C) 2008-2009  Tejun Heo &lt;tj@kernel.org&gt;</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  This program can be distributed under the terms of the GNU GPL.</span></div><div class="line"><span class="comment">  See the file COPYING.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">*/</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define FUSE_USE_VERSION 31</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;cuse_lowlevel.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="fuse__opt_8h.html">fuse_opt.h</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stddef.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;errno.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="ioctl_8h.html">ioctl.h</a>&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> *cusexmp_buf;</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">size_t</span> cusexmp_size;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *usage =</div><div class="line"><span class="stringliteral">&quot;usage: cusexmp [options]\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;options:\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;    --help|-h             print this help message\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;    --maj=MAJ|-M MAJ      device major number\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;    --min=MIN|-m MIN      device minor number\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;    --name=NAME|-n NAME   device name (mandatory)\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;    -d   -o debug         enable debug output (implies -f)\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;    -f                    foreground operation\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;    -s                    disable multi-threaded operation\n&quot;</span></div><div class="line"><span class="stringliteral">&quot;\n&quot;</span>;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> cusexmp_resize(<span class="keywordtype">size_t</span> new_size)</div><div class="line">{</div><div class="line">        <span class="keywordtype">void</span> *new_buf;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (new_size == cusexmp_size)</div><div class="line">                <span class="keywordflow">return</span> 0;</div><div class="line"></div><div class="line">        new_buf = realloc(cusexmp_buf, new_size);</div><div class="line">        <span class="keywordflow">if</span> (!new_buf &amp;&amp; new_size)</div><div class="line">                <span class="keywordflow">return</span> -ENOMEM;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (new_size &gt; cusexmp_size)</div><div class="line">                memset(new_buf + cusexmp_size, 0, new_size - cusexmp_size);</div><div class="line"></div><div class="line">        cusexmp_buf = new_buf;</div><div class="line">        cusexmp_size = new_size;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> cusexmp_expand(<span class="keywordtype">size_t</span> new_size)</div><div class="line">{</div><div class="line">        <span class="keywordflow">if</span> (new_size &gt; cusexmp_size)</div><div class="line">                <span class="keywordflow">return</span> cusexmp_resize(new_size);</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> cusexmp_open(<a class="code" href="fuse__lowlevel_8h.html#a33e2aa4a8905a05397292ae047cd2257">fuse_req_t</a> req, <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        <a class="code" href="fuse__lowlevel_8h.html#a170f8c6b953d70928e83bcecee43bfdc">fuse_reply_open</a>(req, fi);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> cusexmp_read(<a class="code" href="fuse__lowlevel_8h.html#a33e2aa4a8905a05397292ae047cd2257">fuse_req_t</a> req, <span class="keywordtype">size_t</span> size, off_t off,</div><div class="line">                         <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        (void)fi;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (off &gt;= cusexmp_size)</div><div class="line">                off = cusexmp_size;</div><div class="line">        <span class="keywordflow">if</span> (size &gt; cusexmp_size - off)</div><div class="line">                size = cusexmp_size - off;</div><div class="line"></div><div class="line">        <a class="code" href="fuse__lowlevel_8h.html#a300a88b63ab7c8ca92853a97486448c0">fuse_reply_buf</a>(req, cusexmp_buf + off, size);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> cusexmp_write(<a class="code" href="fuse__lowlevel_8h.html#a33e2aa4a8905a05397292ae047cd2257">fuse_req_t</a> req, <span class="keyword">const</span> <span class="keywordtype">char</span> *buf, <span class="keywordtype">size_t</span> size,</div><div class="line">                          off_t off, <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi)</div><div class="line">{</div><div class="line">        (void)fi;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (cusexmp_expand(off + size)) {</div><div class="line">                <a class="code" href="fuse__lowlevel_8h.html#a2553c03f9a63c75e609e67f90a3a5d88">fuse_reply_err</a>(req, ENOMEM);</div><div class="line">                <span class="keywordflow">return</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        memcpy(cusexmp_buf + off, buf, size);</div><div class="line">        <a class="code" href="fuse__lowlevel_8h.html#aa3cfa73f61d6ef461ab5a3fbf859eb97">fuse_reply_write</a>(req, size);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> fioc_do_rw(<a class="code" href="fuse__lowlevel_8h.html#a33e2aa4a8905a05397292ae047cd2257">fuse_req_t</a> req, <span class="keywordtype">void</span> *addr, <span class="keyword">const</span> <span class="keywordtype">void</span> *in_buf,</div><div class="line">                       <span class="keywordtype">size_t</span> in_bufsz, <span class="keywordtype">size_t</span> out_bufsz, <span class="keywordtype">int</span> is_read)</div><div class="line">{</div><div class="line">        <span class="keyword">const</span> <span class="keyword">struct </span>fioc_rw_arg *arg;</div><div class="line">        <span class="keyword">struct </span>iovec in_iov[2], out_iov[3], iov[3];</div><div class="line">        <span class="keywordtype">size_t</span> cur_size;</div><div class="line"></div><div class="line">        <span class="comment">/* read in arg */</span></div><div class="line">        in_iov[0].iov_base = addr;</div><div class="line">        in_iov[0].iov_len = <span class="keyword">sizeof</span>(*arg);</div><div class="line">        <span class="keywordflow">if</span> (!in_bufsz) {</div><div class="line">                <a class="code" href="fuse__lowlevel_8h.html#a940683d07df12c24f56b4363aed90e4d">fuse_reply_ioctl_retry</a>(req, in_iov, 1, NULL, 0);</div><div class="line">                <span class="keywordflow">return</span>;</div><div class="line">        }</div><div class="line">        arg = in_buf;</div><div class="line">        in_buf += <span class="keyword">sizeof</span>(*arg);</div><div class="line">        in_bufsz -= <span class="keyword">sizeof</span>(*arg);</div><div class="line"></div><div class="line">        <span class="comment">/* prepare size outputs */</span></div><div class="line">        out_iov[0].iov_base =</div><div class="line">                addr + offsetof(<span class="keyword">struct</span> fioc_rw_arg, prev_size);</div><div class="line">        out_iov[0].iov_len = <span class="keyword">sizeof</span>(arg-&gt;prev_size);</div><div class="line"></div><div class="line">        out_iov[1].iov_base =</div><div class="line">                addr + offsetof(<span class="keyword">struct</span> fioc_rw_arg, new_size);</div><div class="line">        out_iov[1].iov_len = <span class="keyword">sizeof</span>(arg-&gt;new_size);</div><div class="line"></div><div class="line">        <span class="comment">/* prepare client buf */</span></div><div class="line">        <span class="keywordflow">if</span> (is_read) {</div><div class="line">                out_iov[2].iov_base = arg-&gt;buf;</div><div class="line">                out_iov[2].iov_len = arg-&gt;size;</div><div class="line">                <span class="keywordflow">if</span> (!out_bufsz) {</div><div class="line">                        <a class="code" href="fuse__lowlevel_8h.html#a940683d07df12c24f56b4363aed90e4d">fuse_reply_ioctl_retry</a>(req, in_iov, 1, out_iov, 3);</div><div class="line">                        <span class="keywordflow">return</span>;</div><div class="line">                }</div><div class="line">        } <span class="keywordflow">else</span> {</div><div class="line">                in_iov[1].iov_base = arg-&gt;buf;</div><div class="line">                in_iov[1].iov_len = arg-&gt;size;</div><div class="line">                <span class="keywordflow">if</span> (arg-&gt;size &amp;&amp; !in_bufsz) {</div><div class="line">                        <a class="code" href="fuse__lowlevel_8h.html#a940683d07df12c24f56b4363aed90e4d">fuse_reply_ioctl_retry</a>(req, in_iov, 2, out_iov, 2);</div><div class="line">                        <span class="keywordflow">return</span>;</div><div class="line">                }</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="comment">/* we&#39;re all set */</span></div><div class="line">        cur_size = cusexmp_size;</div><div class="line">        iov[0].iov_base = &amp;cur_size;</div><div class="line">        iov[0].iov_len = <span class="keyword">sizeof</span>(cur_size);</div><div class="line"></div><div class="line">        iov[1].iov_base = &amp;cusexmp_size;</div><div class="line">        iov[1].iov_len = <span class="keyword">sizeof</span>(cusexmp_size);</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (is_read) {</div><div class="line">                <span class="keywordtype">size_t</span> off = arg-&gt;offset;</div><div class="line">                <span class="keywordtype">size_t</span> size = arg-&gt;size;</div><div class="line"></div><div class="line">                <span class="keywordflow">if</span> (off &gt;= cusexmp_size)</div><div class="line">                        off = cusexmp_size;</div><div class="line">                <span class="keywordflow">if</span> (size &gt; cusexmp_size - off)</div><div class="line">                        size = cusexmp_size - off;</div><div class="line"></div><div class="line">                iov[2].iov_base = cusexmp_buf + off;</div><div class="line">                iov[2].iov_len = size;</div><div class="line">                <a class="code" href="fuse__lowlevel_8h.html#a37381eb84c39e5fe3af9f3ef507aeeb7">fuse_reply_ioctl_iov</a>(req, size, iov, 3);</div><div class="line">        } <span class="keywordflow">else</span> {</div><div class="line">                <span class="keywordflow">if</span> (cusexmp_expand(arg-&gt;offset + in_bufsz)) {</div><div class="line">                        <a class="code" href="fuse__lowlevel_8h.html#a2553c03f9a63c75e609e67f90a3a5d88">fuse_reply_err</a>(req, ENOMEM);</div><div class="line">                        <span class="keywordflow">return</span>;</div><div class="line">                }</div><div class="line"></div><div class="line">                memcpy(cusexmp_buf + arg-&gt;offset, in_buf, in_bufsz);</div><div class="line">                <a class="code" href="fuse__lowlevel_8h.html#a37381eb84c39e5fe3af9f3ef507aeeb7">fuse_reply_ioctl_iov</a>(req, in_bufsz, iov, 2);</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> cusexmp_ioctl(<a class="code" href="fuse__lowlevel_8h.html#a33e2aa4a8905a05397292ae047cd2257">fuse_req_t</a> req, <span class="keywordtype">int</span> cmd, <span class="keywordtype">void</span> *arg,</div><div class="line">                          <span class="keyword">struct</span> <a class="code" href="structfuse__file__info.html">fuse_file_info</a> *fi, <span class="keywordtype">unsigned</span> flags,</div><div class="line">                          <span class="keyword">const</span> <span class="keywordtype">void</span> *in_buf, <span class="keywordtype">size_t</span> in_bufsz, <span class="keywordtype">size_t</span> out_bufsz)</div><div class="line">{</div><div class="line">        <span class="keywordtype">int</span> is_read = 0;</div><div class="line"></div><div class="line">        (void)fi;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (flags &amp; <a class="code" href="fuse__common_8h.html#ade38f8e8c463cd40af5bfeeebfa99486">FUSE_IOCTL_COMPAT</a>) {</div><div class="line">                <a class="code" href="fuse__lowlevel_8h.html#a2553c03f9a63c75e609e67f90a3a5d88">fuse_reply_err</a>(req, ENOSYS);</div><div class="line">                <span class="keywordflow">return</span>;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">switch</span> (cmd) {</div><div class="line">        <span class="keywordflow">case</span> FIOC_GET_SIZE:</div><div class="line">                <span class="keywordflow">if</span> (!out_bufsz) {</div><div class="line">                        <span class="keyword">struct </span>iovec iov = { arg, <span class="keyword">sizeof</span>(size_t) };</div><div class="line"></div><div class="line">                        <a class="code" href="fuse__lowlevel_8h.html#a940683d07df12c24f56b4363aed90e4d">fuse_reply_ioctl_retry</a>(req, NULL, 0, &amp;iov, 1);</div><div class="line">                } <span class="keywordflow">else</span></div><div class="line">                        <a class="code" href="fuse__lowlevel_8h.html#adf7f34f470c04f276b7091ad3b3dcb31">fuse_reply_ioctl</a>(req, 0, &amp;cusexmp_size,</div><div class="line">                                         <span class="keyword">sizeof</span>(cusexmp_size));</div><div class="line">                <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">        <span class="keywordflow">case</span> FIOC_SET_SIZE:</div><div class="line">                <span class="keywordflow">if</span> (!in_bufsz) {</div><div class="line">                        <span class="keyword">struct </span>iovec iov = { arg, <span class="keyword">sizeof</span>(size_t) };</div><div class="line"></div><div class="line">                        <a class="code" href="fuse__lowlevel_8h.html#a940683d07df12c24f56b4363aed90e4d">fuse_reply_ioctl_retry</a>(req, &amp;iov, 1, NULL, 0);</div><div class="line">                } <span class="keywordflow">else</span> {</div><div class="line">                        cusexmp_resize(*(<span class="keywordtype">size_t</span> *)in_buf);</div><div class="line">                        <a class="code" href="fuse__lowlevel_8h.html#adf7f34f470c04f276b7091ad3b3dcb31">fuse_reply_ioctl</a>(req, 0, NULL, 0);</div><div class="line">                }</div><div class="line">                <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">        <span class="keywordflow">case</span> FIOC_READ:</div><div class="line">                is_read = 1;</div><div class="line">                <span class="comment">/* fall through */</span></div><div class="line">        <span class="keywordflow">case</span> FIOC_WRITE:</div><div class="line">                fioc_do_rw(req, arg, in_buf, in_bufsz, out_bufsz, is_read);</div><div class="line">                <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">                <a class="code" href="fuse__lowlevel_8h.html#a2553c03f9a63c75e609e67f90a3a5d88">fuse_reply_err</a>(req, EINVAL);</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">struct </span>cusexmp_param {</div><div class="line">        <span class="keywordtype">unsigned</span>                major;</div><div class="line">        <span class="keywordtype">unsigned</span>                minor;</div><div class="line">        <span class="keywordtype">char</span>                    *dev_name;</div><div class="line">        <span class="keywordtype">int</span>                     is_help;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="preprocessor">#define CUSEXMP_OPT(t, p) { t, offsetof(struct cusexmp_param, p), 1 }</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">struct </span><a class="code" href="structfuse__opt.html">fuse_opt</a> cusexmp_opts[] = {</div><div class="line">        CUSEXMP_OPT(<span class="stringliteral">&quot;-M %u&quot;</span>,            major),</div><div class="line">        CUSEXMP_OPT(<span class="stringliteral">&quot;--maj=%u&quot;</span>,         major),</div><div class="line">        CUSEXMP_OPT(<span class="stringliteral">&quot;-m %u&quot;</span>,            minor),</div><div class="line">        CUSEXMP_OPT(<span class="stringliteral">&quot;--min=%u&quot;</span>,         minor),</div><div class="line">        CUSEXMP_OPT(<span class="stringliteral">&quot;-n %s&quot;</span>,            dev_name),</div><div class="line">        CUSEXMP_OPT(<span class="stringliteral">&quot;--name=%s&quot;</span>,        dev_name),</div><div class="line">        <a class="code" href="fuse__opt_8h.html#a371d830a8aedd9e3f96d9bb31876a8f1">FUSE_OPT_KEY</a>(<span class="stringliteral">&quot;-h&quot;</span>,              0),</div><div class="line">        <a class="code" href="fuse__opt_8h.html#a371d830a8aedd9e3f96d9bb31876a8f1">FUSE_OPT_KEY</a>(<span class="stringliteral">&quot;--help&quot;</span>,          0),</div><div class="line">        <a class="code" href="fuse__opt_8h.html#aca35962e17d189ceb5447f8eea11bd33">FUSE_OPT_END</a></div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> cusexmp_process_arg(<span class="keywordtype">void</span> *data, <span class="keyword">const</span> <span class="keywordtype">char</span> *arg, <span class="keywordtype">int</span> key,</div><div class="line">                               <span class="keyword">struct</span> <a class="code" href="structfuse__args.html">fuse_args</a> *outargs)</div><div class="line">{</div><div class="line">        <span class="keyword">struct </span>cusexmp_param *param = data;</div><div class="line"></div><div class="line">        (void)outargs;</div><div class="line">        (void)arg;</div><div class="line"></div><div class="line">        <span class="keywordflow">switch</span> (key) {</div><div class="line">        <span class="keywordflow">case</span> 0:</div><div class="line">                param-&gt;is_help = 1;</div><div class="line">                fprintf(stderr, <span class="stringliteral">&quot;%s&quot;</span>, usage);</div><div class="line">                <span class="keywordflow">return</span> <a class="code" href="fuse__opt_8h.html#a21602e6a0fff64fc9c7b642d12382094">fuse_opt_add_arg</a>(outargs, <span class="stringliteral">&quot;-ho&quot;</span>);</div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">                <span class="keywordflow">return</span> 1;</div><div class="line">        }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">struct </span>cuse_lowlevel_ops cusexmp_clop = {</div><div class="line">        .open           = cusexmp_open,</div><div class="line">        .read           = cusexmp_read,</div><div class="line">        .write          = cusexmp_write,</div><div class="line">        .ioctl          = cusexmp_ioctl,</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">        <span class="keyword">struct </span><a class="code" href="structfuse__args.html">fuse_args</a> args = <a class="code" href="fuse__opt_8h.html#a9bea40fe56b18be9aa110185ab7387ed">FUSE_ARGS_INIT</a>(argc, argv);</div><div class="line">        <span class="keyword">struct </span>cusexmp_param param = { 0, 0, NULL, 0 };</div><div class="line">        <span class="keywordtype">char</span> dev_name[128] = <span class="stringliteral">&quot;DEVNAME=&quot;</span>;</div><div class="line">        <span class="keyword">const</span> <span class="keywordtype">char</span> *dev_info_argv[] = { dev_name };</div><div class="line">        <span class="keyword">struct </span>cuse_info ci;</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (<a class="code" href="fuse__opt_8h.html#a539ef1f571c34f516c60c4cbe2901c0e">fuse_opt_parse</a>(&amp;args, &amp;param, cusexmp_opts, cusexmp_process_arg)) {</div><div class="line">                printf(<span class="stringliteral">&quot;failed to parse option\n&quot;</span>);</div><div class="line">                <span class="keywordflow">return</span> 1;</div><div class="line">        }</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> (!param.is_help) {</div><div class="line">                <span class="keywordflow">if</span> (!param.dev_name) {</div><div class="line">                        fprintf(stderr, <span class="stringliteral">&quot;Error: device name missing\n&quot;</span>);</div><div class="line">                        <span class="keywordflow">return</span> 1;</div><div class="line">                }</div><div class="line">                strncat(dev_name, param.dev_name, <span class="keyword">sizeof</span>(dev_name) - 9);</div><div class="line">        }</div><div class="line"></div><div class="line">        memset(&amp;ci, 0, <span class="keyword">sizeof</span>(ci));</div><div class="line">        ci.dev_major = param.major;</div><div class="line">        ci.dev_minor = param.minor;</div><div class="line">        ci.dev_info_argc = 1;</div><div class="line">        ci.dev_info_argv = dev_info_argv;</div><div class="line">        ci.flags = CUSE_UNRESTRICTED_IOCTL;</div><div class="line"></div><div class="line">        <span class="keywordflow">return</span> cuse_lowlevel_main(args.<a class="code" href="structfuse__args.html#a501883d1eababa08e05b0c802b31e11d">argc</a>, args.<a class="code" href="structfuse__args.html#a6f90bec2356aff03de79baaca65276b6">argv</a>, &amp;ci, &amp;cusexmp_clop,</div><div class="line">                                  NULL);</div><div class="line">}</div></div><!-- fragment --> 
<p class="definition">Definition in file <a class="el" href="cuse_8c_source.html">cuse.c</a>.</p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
